using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameFrameworkLibraly.BaseObjects
{
    public class AnimatedObject:SpriteObject
    {

        private int _elapsedTime;
        private int _currentFrame;

        public AnimatedTexture2D AnimatedTexture { get; set; }


        public AnimatedObject(MyGame game, Vector2 position, AnimatedTexture2D animatedTexture2D): base(game, position, animatedTexture2D.SpriteTexture)
        {
        }



        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            _elapsedTime += gameTime.ElapsedGameTime.Milliseconds;
            if (_elapsedTime > AnimatedTexture.TimeForFrame)
            {
                _elapsedTime = 0;
                _currentFrame = (_currentFrame + 1) % AnimatedTexture.FrameCount;
                SourceRect = AnimatedTexture.GetSourceRectangle(_currentFrame);
            }
        }
    }
}
